package cuiyt.leetcode.dichotomy.demoa;

/**
 * @author cyt
 * @create 2020-09-06 14:40
 */
public class Ta {

    public static void main(String[] args) {
        int[] ints = new int[]{-1, 0, 3, 5, 9, 12};
        Ta ta = new Ta();
        int search = ta.search(ints, 0);
        System.out.println(search);
    }


    public int search(int[] nums, int target) {
        int l = 0;
        int r = nums.length - 1;
        while (l <= r) {
            int mid = l + (r - l) / 2;
            if (target > nums[mid]) {
                l = mid + 1;
            } else if (target < nums[mid]) {
                r = mid - 1;
            } else {
                return mid;
            }
        }
        return -1;
    }

}
